package com.lenovo.nova.widget.baseview;

import com.lenovo.nova.util.Applications;
import com.lenovo.nova.util.Applications.OnInputModeChangeListener;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.ImageButton;
import com.lenovo.nova.util.DevicesUtil;


public class CustomImageButton extends ImageButton implements OnInputModeChangeListener{

	public CustomImageButton(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		initLayout(context,null);
	}

	public CustomImageButton(Context context, AttributeSet attrs) {
		super(context, attrs);
		initLayout(context,attrs);
	}


	public CustomImageButton(Context context) {
		super(context);
		initLayout(context,null);
	}

	private void initLayout(Context context, AttributeSet attrs) {
		
	}

	@Override
	protected void onAttachedToWindow() {
        try {
            Applications.get().addOnInputModeChangeListener(this);
        } catch (Exception e) {

        }
        super.onAttachedToWindow();
	}
	
	@Override
	protected void onDetachedFromWindow() {
		Applications.get().removeOnInputChangeListener(this);
		super.onDetachedFromWindow();
	}
	
	@SuppressLint("NewApi")
	@Override
	public void onInputModeChange(boolean isInTouchMode) {
		if(isInTouchMode){
            DevicesUtil.getInstance().ensureInputMode(this);
		}else{
			if(isHovered()){
				setHovered(false);
			}
		}
	}
}
